﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ShortestPathTest1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            
        }

        [DllImport("kernel32.dll", EntryPoint = "AllocConsole", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        private static extern int AllocConsole();

        private void DrawEllipse(Point point, string i)
        {
            var vertexBrush = new SolidColorBrush(Colors.BlueViolet);
            var vertex2 = new Ellipse()
            {
                Fill = vertexBrush,
                Width = 5,
                Height = 5
            };
            Canvas.SetLeft(vertex2, point.X - 2.5);
            Canvas.SetTop(vertex2, point.Y - 2.5);
            DrawLabel(point, i);
            GraphCanvas.Children.Add(vertex2);
        }

        private void DrawLine(Point point1, Point point2, double d)
        {
            var vertexBrush = new SolidColorBrush(Colors.BlueViolet);
            var line = new Line
            {
                Stroke = vertexBrush,
                X1 = point1.X,
                X2 = point2.X,
                Y1 = point1.Y,
                Y2 = point2.Y
            };

            DrawLabel(new Point(Math.Abs((point1.X + point2.X)/2), Math.Abs((point1.Y + point2.Y)/2)), d.ToString());
            GraphCanvas.Children.Add(line);
        }

        private void DrawLabel(Point point, string content)
        {
            Label label = new Label() { Content = content };

            Canvas.SetLeft(label,point.X);
            Canvas.SetTop(label, point.Y);
            GraphCanvas.Children.Add(label);
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            int fromId = 0;
            int toId = 3;
            /*var routes1 = new List<Route>() {new Route() {Id = 1}, new Route() {Id = 2}, new Route() {Id = 3}};
            var routes2 = new List<Route>() {new Route() {Id = 1}, new Route() {Id = 2}};
            var routes3 = new List<Route>() {new Route() {Id = 1}, new Route() {Id = 4}, new Route() {Id = 5}};
            var edges = new List<Edge>()
                            {
                                new Edge
                                    {
                                        From = new Vertex {Id = 0, Routes = routes1},
                                        To = new Vertex {Id = 1, Routes = routes1}
                                    },
                                new Edge
                                    {
                                        From = new Vertex {Id = 1, Routes = routes1},
                                        To = new Vertex {Id = 2, Routes = routes2}
                                    },
                                new Edge
                                    {
                                        From = new Vertex {Id = 2, Routes = routes2},
                                        To = new Vertex {Id = 3, Routes = routes1}
                                    },
                                new Edge
                                    {
                                        From = new Vertex {Id = 1, Routes = routes1},
                                        To = new Vertex {Id = 4, Routes = routes3}
                                    },
                                new Edge
                                    {
                                        From = new Vertex {Id = 4, Routes = routes3},
                                        To = new Vertex {Id = 3, Routes = routes1}
                                    },
                            };

            var graph = new Graph() {Edges = edges};

            var node = graph.ExpandGraphRecursive(fromId, fromId, toId, -1);
            var allPathes = new List<List<Edge>>();

            var path = node.GetPathes(toId);*/
        }
    }

    
}
